import { CsvManager_blxf } from "../Manager/CsvManager";
import { EnumManager_blxf } from "../Manager/EnumManager";
import { ConfigModule_blxf } from "../Module/ConfigModule";
import { NumModule_blxf } from "../Module/NumModule";
import PublicModule_blxf from "../Module/PublicModule";
import { UtilsModule_blxf } from "../Module/UtilsModule";
import GameData_blxf from "./GameData";
import BaseShopData_blxf from "./ShopData";
import { BaseTargetData_blxf } from "./TargetData";



/** 基础摊位数据 */
export class BaseVendorData_blxf {

    public constructor ( data: object ) {
        this.vendorId = data['vendorId'];
        this.vendorLv = data['vendorLv'];
        this.isUnlock = data['isUnlock'];
        this.unlockNum = Number(data['UnlockNum']);
        this.unlockType = Number(data['UnlockType']);
        this.shopList = [];
        this.isChoose = false;

        this.onInitMaxNum_blxf();

        if (isNaN(this.unlockNum )) this.unlockNum  = data['UnlockNum'];
    }

    /** 摊位解锁类型 */
    unlockType : number = 0;
    /** 摊位解锁数量 */
    unlockNum  : number = 0;

    /** 最多可摆放商品数 */
    maxNum   : number = 10;
    /** 基础商品数 */
    baseNum  : number = 1;
    /** 是否被选中 */
    isChoose : boolean = false;
    /** 是否解锁 */
    isUnlock : boolean = false;


    /** 摊位id */
    vendorId : number = -1;
    /** 摊位商品数量(排) */
    shopNum  : number = 0;
    /** 摊位商品列表 */
    shopList : BaseShopData_blxf[] = [];
    /** 摊位等级 */
    vendorLv : number = 1;

    /** 初始化篮子需求物品数 */
    onInitMaxNum_blxf () {
        this.maxNum = 10;
    }

    /** 检测摊位是否解锁 */
    onCheckUnlockVendor_blxf () {
        return this.isUnlock;
    }

    /** 检测摊位可操作商品id */
    onCheckShopId_blxf () {
        let _index = this.shopNum - 1;
        let _shopData = this.shopList[ _index ];
        if ( _shopData ) return _shopData.shopId;
    }

    /** 获取标记摊位id */
    getMarkVendorId_blxf () {
        let _markVendorId: number = VendorData_blxf.instance.getMarkVendorId_blxf();
        return _markVendorId;
    }

    /** 获取摊位id */
    getVendorId_blxf () {
        return this.vendorId;
    }

    /** 获取商品数 */
    getShopNum_blxf () {
        return this.shopList.length;
    }

    /** 获取最大商品数 */
    getMaxShopNum_blxf () {
        return this.maxNum;
    }

    /**
     * 检测是否可解锁摊位
     */
    onCheckIsUnlockVendor_blxf ( isTouch: boolean = false ) {
        let _isVideo: boolean = this.onCheckVideoVendor_blxf();
        if ( _isVideo ) return;

        let { NUM_PASS, NUM_VIDEO } = EnumManager_blxf.gameNumType;
        let _isPass: boolean = NUM_PASS == this.unlockType;
        if ( !_isPass ) return;

        let _isUnlock: boolean = true, _vendorId: number = 1;
        let _bigPassNum = GameData_blxf.instance.getBigPassNum_blxf();
        let { CSV_VENDOR } = EnumManager_blxf.instance.getGameCsvType();
        let _cfgVendorData = CsvManager_blxf.instance.getCsvDataByName_blxf( CSV_VENDOR );
        _cfgVendorData.forEach( item => {
            let { VendorId, UnlockType, UnlockNum } = item;
            if ( !_isUnlock ) return;
            if ( UnlockType == NUM_VIDEO ) return;
            if ( UnlockType != NUM_PASS ) return;
            if ( UnlockNum - this.unlockNum >= 0 ) return;
            if ( UnlockNum - _bigPassNum > 0 ) return;

            let _isUnlockVendor: boolean = !!GameData_blxf.instance.getVendorData_blxf( VendorId );
            if ( _isUnlockVendor ) return;

            _isUnlock = false;
            _vendorId = VendorId;
        })

        if ( !_isUnlock && isTouch ) UtilsModule_blxf.onTips_blxf(`请先解锁摊位${_vendorId}`);
        return _isUnlock;
    }

    /** 获取商品id列表 */
    getShopIdList_blxf () {
        let _shopIdList: number[] = [];

        this.shopList.forEach( item =>{
            let _shopId: number = item.getShopId_blxf();
            _shopId && _shopId != -1 && _shopIdList.push( _shopId );
        })

        return _shopIdList;
    }

    /** 获取物品类型数 */
    getShopIdNum_demo () {
        let _shopIds: number[] = [];
        let _shopIdList: number[] = this.getShopIdList_blxf();
        _shopIdList.forEach( shopId =>{
            !_shopIds.includes(shopId) && _shopIds.push( shopId );
        })
        return _shopIds.length;
    }

    /** 获取商品额外列表 */
    getShopExtraList_blxf () {
        let _extraIconList: boolean[] = [];

        this.shopList.forEach( item =>{
            let _shopId: number = item.getShopId_blxf();
            let _isExtraIcon: boolean = item.getIsExtraIcon_blxf();
            _shopId && _shopId != -1 && _extraIconList.push( _isExtraIcon );
        })

        return _extraIconList;
    }

    /**
     * 获取可操作商品数
     * @param checkShopId 
     * @returns 返回可操作商品数
     */
    getShopNumByShopId_blxf ( checkShopId: number = -1 ) {
        let _shopNum: number = 0;

        if ( checkShopId == -1 ) {
            checkShopId = this.onCheckShopId_blxf();
        }

        let _index: number;
        let _totalNum: number = this.shopList.length;
        for ( _index = _totalNum - 1; _index >= 0; _index-- ) {
            let _shopData: BaseShopData_blxf = this.shopList[ _index ];
            let _shopId: number = _shopData.getShopId_blxf();
            if ( _shopId != checkShopId ) break;

            _shopNum += 1;
        }

        return _shopNum;
    }

    /** 检测是否是临时摊位 */
    onCheckVideoVendor_blxf () {
        let { NUM_VIDEO } = EnumManager_blxf.gameNumType;
        return this.unlockType == NUM_VIDEO;
    }

    /** 检测是否满商品数 */
    onCheckIsAllShop_blxf () {
        let _shopNum: number = this.getShopNumByShopId_blxf();
        let _isAllShop: boolean = _shopNum == this.maxNum;
        return _isAllShop;
    }

    /**
     * 检测是否被标记
     * @returns 是否被标记
     */
    onCheckIsMark_blxf () {
        let _markVendorId: number = this.getMarkVendorId_blxf();
        let _isMark: boolean = this.vendorId == _markVendorId;
        return _isMark;
    }

    /** 获取可添加商品数 */
    getMaxAddShopNum_blxf () {
        return this.maxNum - this.shopNum;
    }

    /** 获取可添加商品总数 */
    getMaxAddShopTotalNum_blxf () {
        let _maxShopNum: number = this.getMaxAddShopNum_blxf();
        let _totalNum: number = _maxShopNum * this.baseNum;
        return _totalNum;
    }

    /** 解锁摊位 */
    unlockVendor_blxf ( isUnlock: boolean = true ) {
        this.isUnlock = isUnlock;
    }

    /** 清除摊位商品 */
    clearShop_blxf () {
        if ( !this.onCheckUnlockVendor_blxf() ) return;

        this.shopNum = 0;
        this.shopList.length = 0;

        this.saveVendorShopList_blxf();
    }

    /** 设置摊位等级 */
    setVendorLevel_blxf ( addLv: number ) {
        this.vendorLv += addLv;

        GameData_blxf.instance.setVendorLv_blxf( this.vendorId, addLv );
    }

    /**
     * 添加商品
     * @param shopData 商品相关数据 { shopId: 商品id }
     * @param isBtn 是否上货按钮添加
     * @param return 返回添加的商品数据
     */
    addShop_blxf ( shopId: number, isBtn: boolean = false, isExtraIcon: boolean = false, isShowSpine: boolean = false, index: number = -1 ) {
        let _addShopData: BaseShopData_blxf;

        if ( !shopId ) {
            UtilsModule_blxf.instance.Log_blxf(`addShop_blxf 参数错误, 缺少shopId`, 2);
            return _addShopData;
        }

        let _isAll = this.shopNum >= this.maxNum;
        if ( _isAll ) return _addShopData;

        this.shopNum += 1;

        let shopNum      : number = this.baseNum;
        let shopIndex    : number = this.shopNum - 1;
        let _cfgShopData : object = VendorData_blxf.instance.findShopData_blxf( shopId );

        // if ( isExtraIcon === -1 ) {
        //     isExtraIcon = NumModule_blxf.instance.isRatio_blxf( 0.5 );
        // }

        // if ( isShowSpine ) cc.error('isShowSpine >>', isShowSpine);
        let baseShopData : object = { ..._cfgShopData, shopNum, shopIndex, isExtraIcon, isShowSpine };
        _addShopData = new BaseShopData_blxf(baseShopData);

        if ( index == -1 ) {
            this.shopList[ shopIndex ] = _addShopData;
        } else {
            this.shopList.splice( index, 0, _addShopData );
        }

        // 保存数据
        this.saveVendorShopList_blxf();
        // UtilsModule_blxf.instance.Log_blxf(`${isBtn ? '上货' : '《4》标记执行成功后'} <添加商品> : 摊位id && 商品id => ${this.vendorId} & ${shopId}`);

        return _addShopData;
    };

    /**
     * 移除商品
     * @param flag 是否递归
     */
    removeShop_blxf ( flag: boolean = false ) {
        let _removeShopData: BaseShopData_blxf;

        let shopId: number = this.onCheckShopId_blxf();
        if ( !shopId ) {
            // UtilsModule_blxf.instance.Log_blxf(`removeShop_blxf 参数错误, 缺少shopId`, 2)
            return _removeShopData;
        }

        let _checkIndex = this.shopNum - 1;
        let _shopData: BaseShopData_blxf = this.shopList[ _checkIndex ]; 
        if ( !_shopData ) {
            if ( !flag ) UtilsModule_blxf.instance.Log_blxf(`摊位已经清空，移除商品失败 shopId = ${shopId}, vendorId = ${this.vendorId}`, 3);
            return _removeShopData;
        }

        let _isRemove = _shopData.onCheckShopId_blxf( shopId );
        if ( !_isRemove ) {
            if ( !flag ) UtilsModule_blxf.instance.Log_blxf(`移除商品失败 shopId = ${shopId}, vendorId = ${this.vendorId}`, 3);
            return _removeShopData;
        }

        this.shopNum -= 1;
        _removeShopData = this.shopList.pop();

        // 临时摊位商品清空时，重新上锁
        this.onRestartVideoVendor_blxf( true );

        // 保存数据
        this.saveVendorShopList_blxf();
        // UtilsModule_blxf.instance.Log_blxf(`《3》摊位移除商品信息: 摊位id & 摊位剩余商品数 => ${this.vendorId} & ${this.shopList.length}`);

        return _removeShopData;
    };

    /** 重置视频摊位 */
    onRestartVideoVendor_blxf ( isCheckNum: boolean = false ) {
        if ( !this.isUnlock ) return;
        
        let _isRestartVideoVendor: boolean = this.onCheckVideoVendor_blxf() && ( !isCheckNum || this.shopNum == 0 );
        if ( !_isRestartVideoVendor ) return;

        this.isUnlock = false;

        this.setVendorIsUnlock_blxf();

        return true;
    }

    /** 清除商品标记移除 */
    clearShopMarkRemove_blxf () {
        this.shopList.forEach( shopItem =>{
            shopItem.setIsMarkRemove_blxf( false );
        })
    }

    /** 卸货 */
    removeShopByNum_blxf ( shopIds: number[], removeNum: number = 1, intShopData: any[] ) {
        let _isRemove: boolean = false;

        // if ( this.shopNum <= 0 ) return _isRemove;

        // 跳过需求商品
        let _shopIndex: number;
        for ( _shopIndex = this.shopNum - 1; _shopIndex >= 0; _shopIndex-- ) {
            let _shopData = this.shopList[ _shopIndex ];
            // 已标记移除则跳过
            if ( _shopData.getIsMarkRemove_blxf() ) continue;

            let _shopId: number = _shopData.getShopId_blxf();
            if ( shopIds.includes(_shopId) ) continue;

            let _intIndex: number = intShopData.findIndex( item =>{
                return item.shopId == _shopId && item.num > 0;
            })
            // 标记移除
            if ( _intIndex != -1 ) {
                intShopData[ _intIndex ].num -= removeNum;
                _shopData.setIsMarkRemove_blxf( true );
                continue;
            }

            break;
        }
        
        if ( _shopIndex == -1 ) return _isRemove;

        this.shopNum -= removeNum;
        this.shopList.splice(_shopIndex, removeNum);

        // 保存数据
        this.saveVendorShopList_blxf();

        _isRemove = true;
        return _isRemove;
    }

    /**
     * 重置商品列表
     * @param shopId 商品id
     */
    onRestartShopList_blxf ( shopIds: number[] ) {
        let _shopIdList: number[] = [];
        // 设置排序值（目标商品最大、其它相同商品排序值相同）
        this.shopList.forEach( shopItem =>{
            let _itemShopId: number = shopItem.getShopId_blxf();

            let _index: number = shopIds.indexOf( _itemShopId );
            let _isBuyShop: boolean = _index > -1
            let _shopIdIndex: number = _shopIdList.indexOf( _itemShopId );

            let _sortNum: number = _isBuyShop ? (10 - _index) * 99 : _shopIdIndex;
            if ( !_isBuyShop && _shopIdIndex == -1 ) {
                _shopIdList.push( _itemShopId );
                _sortNum = _shopIdList.length - 1;
            }
            shopItem.setShopSortNum_blxf( _sortNum );
        })

        // 重新排序
        this.shopList.sort((a, b) =>{
            return a.getShopSortNum_blxf() - b.getShopSortNum_blxf();
        })

        // 保存数据
        this.saveVendorShopList_blxf();
    }

    /**
     * 重置商品列表
     * @param shopId 商品id
     */
    onRestartShopList_blxf_test ( shopIds: number[], extraIconNumInfo: any = {} ) {
        this.shopNum = 0;
        this.shopList.length = 0;
        shopIds.forEach( shopIdItem =>{
            let _isExtraIcon = extraIconNumInfo[ shopIdItem ] > 0;
            extraIconNumInfo[ shopIdItem ] -= 1;
            this.addShop_blxf( shopIdItem, false, _isExtraIcon );
        })
    }

    /** 检测是否出现单个商品 */
    onCheckShop_blxf () {
        let _shopId: number;
        let _shopNum: number = Math.ceil( this.shopNum / 2 ) * 2;

        for ( let i = 0; i < _shopNum; i++ ) {
            let _shopItem: BaseShopData_blxf = this.shopList[ i ];
            let _itemShopId: number = _shopItem ? _shopItem.getShopId_blxf() : -1;

            if ( i % 2 == 0 ) {
                _shopId = _itemShopId;
            } else {
                let _isAlike: boolean = _shopId == _itemShopId;
                if ( _isAlike ) continue;

                // todo 出现单个处理
                console.warn('出现单个了 >>', this.vendorId);
                this.addShop_blxf( _shopId, false, false, false, i );
            }
        }
    }


    /***** 摊位数据存储 *****/

    /** 保存摊位商品数据 */
    saveVendorShopList_blxf () {
        let _shopList: number[] = [], _extraList: boolean[] = [];
        this.shopList.forEach( shopItem =>{
            shopItem && _shopList.push( shopItem.getShopId_blxf() );
            shopItem && _extraList.push( shopItem.getIsExtraIcon_blxf() );
        })
        GameData_blxf.instance.setVendorShopList_blxf( this.vendorId, _shopList, _extraList );
    }

    /** 设置摊位是否解锁 */
    setVendorIsUnlock_blxf () {
        GameData_blxf.instance.setVendorIsUnlock_blxf( this.vendorId, false );
    }

    /** 清除摊位商品 */
    clearVendorShopList_blxf () {
        this.shopList.length = 0;
        this.saveVendorShopList_blxf();
    }
}



const {ccclass, property} = cc._decorator;

/** 主玩法游戏数据库 */
@ccclass
export class VendorData_blxf {

    private constructor () {};

    private static _VendorData_blxf: VendorData_blxf = new VendorData_blxf();

    public static get instance () {
        return this._VendorData_blxf;
    }

    /** 篮子总数 */
    // 1：临时篮子、2：普通篮子、3：需求商品篮子、4：普通篮子
    targetNum          : number = 4;
    /** 需求商品篮子id */
    shopTargetId       : number = 3;
    /** 看视频临时篮子 */
    videoTargetId      : number = 1;

    /** 已解锁篮子id列表 */
    unlockTargetIdList : number[] = [] || [ 3 ] || [ 1, 2, 3, 4 ];
    /** 篮子数据列表 */
    targetDataList     : BaseTargetData_blxf[] = [];

    /** 摊位总数 */
    vendorNum          : number = 9;
    /** 默认解锁摊位Id列表 */
    unlockVendorIdList : number[] = [] || [ 1, 2, 3 ];
    /** 摊位数据列表 */
    vendorDataList     : BaseVendorData_blxf[] = [];

    /** 基础商品数 */
    baseShopNum         : number = 1;

    /** 标记摊位id */
    markVendorId       : number = -1;

    /** 必须上货商品列表 */
    mustAddShopIdList  : number[] = [];
    /** 上货商品列表 */
    needAddShopIdList  : number[] = [];
    /** 上货商品类型范围 */
    addShopTypeNums    : number[] = [];
    /** 上货商品总数 */
    addShopTotalNum    : number = 0;
    /** 额外上货总数 */
    extraShopTotalNum  : number = 0;
    /** 商品类型总数 */
    shopTypeMaxNum     : number = 0;


    /** 必出所有菜篮子目标商品时摊位数 */
    checkVendorNum     : number = 7;


    /** 添加商品类型数 */
    addShopTypeNum     : number = 0;
    /** 是否上货需要商品 */
    isAddBuyShopId     : boolean = false;

    /** 临时摊位id */
    videoVendorId      : number = 5;

    /** 摊位整数商品数据 */
    _intShopData       : any = null;

    /** 初始化游戏数据 */
    initGamePlayData_blxf () {
        this.initVendorDataList_blxf();
        this.initTargetDataList_blxf();

        // this.onCheckConnectClear_blxf();
    }

    /**
     * 初始化摊位列表
     */
    initVendorDataList_blxf () {
        let vendorIndex: number;

        let _cfgVendorName = EnumManager_blxf.instance.getGameCsvType().CSV_VENDOR;
        let _cfgVendorData = CsvManager_blxf.instance.getCsvDataByName_blxf( _cfgVendorName );
        let _vendorNum = _cfgVendorData.length;
        for ( vendorIndex = 0; vendorIndex < _vendorNum; vendorIndex++ ) {

            let cfgVendorData: object = _cfgVendorData[ vendorIndex ];
            let vendorId: number = Number(cfgVendorData['VendorId']);
            let unlockType: number =  Number(cfgVendorData['UnlockType']);
            // 获取解锁摊位
            let _vendorData = this.newAddVendorIdList_blxf( vendorId );

            // let isUnlock: boolean = this.unlockVendorIdList.includes( vendorId );
            let _saveVendorData: any = GameData_blxf.instance.getVendorData_blxf( vendorId );
            let isUnlock: boolean = _saveVendorData ? _saveVendorData.isUnlock : false;
            // if ( vendorId <= 4 ) isUnlock = true;
            
            let vendorLv: number = GameData_blxf.instance.getVendorLv_blxf( vendorId );

            let baseVendorData: object = { vendorId, vendorLv, isUnlock, ...cfgVendorData };
            let vendorData: BaseVendorData_blxf = new BaseVendorData_blxf( baseVendorData );
            this.vendorDataList[ vendorIndex ] = vendorData;

            if ( !_vendorData ) continue;
            let { shopList, extraList } = _vendorData;
            extraList = extraList || [];
            shopList.forEach( (shopIdItem, index) =>{
                let _isExtraIcon: boolean = extraList[ index ] || false;
                vendorData.addShop_blxf( shopIdItem, false, _isExtraIcon);
            })
        }

        this.onCheckVendorShop_blxf();

        // UtilsModule_blxf.instance.Log_blxf( this.vendorDataList );
    }

    /** 初始化篮子数据 */
    initTargetDataList_blxf () {
        let _cfgTargetName = EnumManager_blxf.instance.getGameCsvType().CSV_TARGET;
        let _cfgTargetData = CsvManager_blxf.instance.getCsvDataByName_blxf( _cfgTargetName );
        this.targetNum = _cfgTargetData.length;

        let targetIndex: number;
        for ( targetIndex = 0; targetIndex < this.targetNum; targetIndex++ ) {

            let targetId: number = targetIndex + 1;
            // 新增解锁菜篮子
            let _targetData = this.newAddTargetIdList_blxf( targetId ) || {};

            let isUnlock: boolean = this.unlockTargetIdList.includes( targetId );
            let buyShopId: number = _targetData.buyShopId || -1;
            let buyShopNum: number = _targetData.shopNum || 0;
            let isRandomShopId: boolean = _targetData.isRandomShopId || true;

            // 兼容：出现目标物品鞭炮
            buyShopId = this.onCheckTargetShopId_blxf( buyShopId );

            let cfgTargetData: object = _cfgTargetData[ targetIndex ];
            let baseTargetData: object = { isUnlock, buyShopId, buyShopNum, isRandomShopId, ...cfgTargetData };
            let targetData: BaseTargetData_blxf = new BaseTargetData_blxf( baseTargetData );
            this.targetDataList[ targetIndex ] = targetData;

            let _isTarget: boolean = targetData.getTargetType_blxf() == 3;
            _isTarget && setTimeout(()=>{
                cc.game.emit('updateGuestShopData_blxf', targetData.getBuyShopId_blxf());
            }, 100)
        }

        // UtilsModule_blxf.instance.Log_blxf( this.targetDataList );
    }

    // 兼容：出现目标物品鞭炮
    onCheckTargetShopId_blxf ( buyShopId: number ) {
        let _isCheck = buyShopId == ConfigModule_blxf.diamondShopId;

        if ( !_isCheck ) return buyShopId;

        buyShopId = this.getTargetShopId_blxf( true,  -1 );
        return buyShopId;
    }

    /** 初始化上货数据 */
    initAddShopData_blxf () {
        let _unlockVendorNum: number = this.getUnlockVendorNum_blxf();
        if ( _unlockVendorNum > 11 ) _unlockVendorNum = 11;
        let { CSV_VENDOR_ADDSHOP } = EnumManager_blxf.instance.getGameCsvType();
        let _cfgAddShopData = CsvManager_blxf.instance.getCsvDataByName_blxf( CSV_VENDOR_ADDSHOP );
        let _data = _cfgAddShopData.find( item => item.VendorNum == _unlockVendorNum );
        if ( !_data ) return;

        let { ShopTypeNum, ShopBaseNum, ExtraShopNum, MaxShopTypeNum } = _data;
        // 随机上货种类
        let [ _min, _max ] = ShopTypeNum.split('_');
        _min = Number( _min ), _max = Number( _max );
        // 随机上货数量
        let [ _minAddNum, _maxAddNum ] = ShopBaseNum.split('_');
        // 视频增益
        let _isVideoBuff: boolean = PublicModule_blxf.onCheckIsVideoBuff_blxf();
        if ( _isVideoBuff ) _maxAddNum = _minAddNum;
        // 负增益
        let _isNegative: boolean = PublicModule_blxf.getIsTriggerNegative_blxf();
        if ( _isNegative && !_isVideoBuff ) _minAddNum = _maxAddNum;

        let _randomAddNum = Number( _minAddNum ) + Math.random() * ( _maxAddNum - _minAddNum );

        this.addShopTypeNums = [ _min ];
        if ( _max ) this.addShopTypeNums.push( _max );
        this.addShopTotalNum = Math.round( _randomAddNum / 2 );
        this.extraShopTotalNum = Number( ExtraShopNum ) / 2;
        this.shopTypeMaxNum = Number( MaxShopTypeNum );

        let _bigPassNum: number = GameData_blxf.instance.getBigPassNum_blxf();
        if ( _bigPassNum == 1 ) this.shopTypeMaxNum -= 1;
    }

    /**
     * 获取必须上货商品列表（上货时目标商品、摊位上已有商品必出）
     */
    initMustShopIdList_blxf () {
        let _shopIdList: number[] = [];
        let [ _minN, _maxN ] = this.addShopTypeNums;
        let _shopTypeNum: number = _minN;
        if ( _maxN ) _shopTypeNum += Math.round(Math.random() * (_maxN - _minN));

        // let _cfgAddShopData = CsvManager_blxf.instance.getVendorAddShopData_blxf();
        // let _percent: string = _cfgAddShopData ? _cfgAddShopData.NormalPercent : '50%';

        // let _isAllTarget: boolean = NumModule_blxf.instance.isChance_blxf( _percent );
        // if ( _isAllTarget ) {
        //     // 所有菜篮子商品id列表
        //     let _targetShopIdList: number[] = this.getTargetShopIdList_blxf();
        //     _shopIdList = _shopIdList.concat( _targetShopIdList );
        // } else {
        //     // 目标篮子商品id
        //     let _targetShopId: number = this.onTargetShopId_blxf( this.shopTargetId );
        //     if ( _targetShopId != -1 ) _shopIdList.push( _targetShopId );
        // }

        // 所有菜篮子商品id列表
        let _targetShopIdList: number[] = this.getTargetShopIdList_blxf();
        _targetShopIdList.sort((a, b) => Math.random() - 0.5);

        // 解锁摊位数大于7时，所有菜篮子目标商品必出，否则只出其中一个菜篮子目标商品
        let _unlockVendorNum: number = this.getUnlockVendorNum_blxf();
        let _isAllTargetShopId: boolean = _unlockVendorNum >= this.checkVendorNum;

        let _endIndex: number = _isAllTargetShopId ? _targetShopIdList.length : 1;
        _shopIdList = _targetShopIdList.splice(0, _endIndex);

        this.isAddBuyShopId = false;
        this.addShopTypeNum = _shopTypeNum;
        
        // 视频增益
        let _isVideoBuff: boolean = PublicModule_blxf.onCheckIsVideoBuff_blxf();
        if ( _isVideoBuff && this.addShopTypeNum >= 2 ) {
            this.addShopTypeNum -= 1;
        }

        // 减益
        if ( !_isVideoBuff && PublicModule_blxf.getIsTriggerNegative_blxf() ) {
            this.addShopTypeNum += 1;
        }

        this.mustAddShopIdList = _shopIdList;
        // cc.log('this.mustAddShopIdList >>', this.mustAddShopIdList, _targetShopIdList);
    }

    /** 初始化上货商品id列表 */
    initAddShopIdList_blxf () {
        // 摊位目标物品 + 已解锁物品
        // 上货数 < 必须上货总类     ==>> 随机
        // 上货数 >= 必须上货总类    ==>> 必须上货数 + 随机

        let _addShopIdList: number[] = [];
        let _addShopNum: number = this.getAddShopTotalNum_blxf(); 
        let _addShopMaxNum: number = this.getVendorAddShopMaxNum_blxf();
        // cc.log('_addShopNum >>', _addShopNum, _addShopMaxNum);
        let _isCheck: boolean = NumModule_blxf.instance.onCompareNum_blxf( _addShopMaxNum, _addShopNum );
        if ( !_isCheck ) _addShopNum = _addShopMaxNum;

        let _shopIdList: number[] = GameData_blxf.instance.getShopIdList_blxf();
        _shopIdList.sort((a, b) => Math.random() - 0.5);

        // 摊位总类数 > 限制总类数
        let _unlockTargetNum: number = GameData_blxf.instance.getTargetNum_blxf();
        let _maxTypeNum: number = [ 6, 8, 12 ][ _unlockTargetNum - 1 ];

        _maxTypeNum = this.shopTypeMaxNum;

        let _vendorShopIdList: number[] = this.getVendorShopIdList_blxf( true );
        let _isMaxNum: boolean = NumModule_blxf.instance.onCompareNum_blxf( _vendorShopIdList.length, _maxTypeNum, true );
        // cc.log('_isMaxNum >>', _isMaxNum, _vendorShopIdList.length, _maxTypeNum, _vendorShopIdList);
        if ( _isMaxNum ) {
            _shopIdList = [ ..._vendorShopIdList ];
        }

        let _mustTypeNum: number = this.addShopTypeNum - this.mustAddShopIdList.length;
        if ( _mustTypeNum > 0 ) {
            let _filterList = _shopIdList.filter( item => !this.mustAddShopIdList.includes(item) );
            this.mustAddShopIdList = this.mustAddShopIdList.concat(_filterList.splice(0, _mustTypeNum));
        }

        let _mustShopNum = this.mustAddShopIdList.length;
        let _isCheckMust: boolean = NumModule_blxf.instance.onCompareNum_blxf( _mustShopNum, _addShopNum );
        // 上货数 < 必须上货总类
        if ( _isCheckMust ) {
            // this.mustAddShopIdList.sort((a, b) => Math.random() - 0.5);
            // this.mustAddShopIdList = this.mustAddShopIdList.splice(0, _addShopNum);
        } else {
            // 上货数 >= 必须上货总类
            _addShopIdList = _addShopIdList.concat( this.mustAddShopIdList );
        }
        // cc.log('_addShopIdList >>', _mustShopNum, _addShopNum, [..._addShopIdList]);

        let _mustShopIdList: number[] = [ ];
        
        _shopIdList.forEach( shopIdItem =>{
            let _isCheck: boolean = _mustShopIdList.includes(shopIdItem) || this.mustAddShopIdList.includes(shopIdItem);
            let _mustNum: number = _mustShopIdList.length;
            if ( !_isCheckMust ) _mustNum += this.mustAddShopIdList.length;
            let _isMax: boolean = _mustNum >= this.addShopTypeNum;
            !_isCheck && !_isMax && _mustShopIdList.push( shopIdItem );
        })

        this.mustAddShopIdList = [ ...this.mustAddShopIdList, ..._mustShopIdList ];
        // cc.log('this.mustAddShopIdList >0>', _shopIdList, [..._mustShopIdList], [...this.mustAddShopIdList]);

        // if ( !_isCheckMust ) {
            let _randomNum = _addShopNum - _addShopIdList.length;
            let _randomIdList: number[] = this.getAddShopRandomIdList_blxf( [], this.mustAddShopIdList, _randomNum );
            _addShopIdList = _addShopIdList.concat( _randomIdList );
        // }

        _addShopIdList.sort((a, b)=> Math.random() - 0.5);

        let _isGui: boolean = GameData_blxf.instance.getIsGuidance_blxf();
        if ( !_isGui ) {
            _addShopIdList = [
                10000, 10001, 10000,
                10000, 10001, 10000,
                10000, 10001, 10001 
            ]
        } else {
            _addShopIdList = UtilsModule_blxf.onCopyList_blxf( _addShopIdList );
            _addShopIdList.length = _addShopNum;
        }

        this.needAddShopIdList = _addShopIdList;
        // cc.log('this.mustAddShopIdList >1>', _addShopNum, _addShopMaxNum);
        // cc.log('this.mustAddShopIdList >2>', this.addShopTypeNum, this.mustAddShopIdList, this.needAddShopIdList);
    }

    /** 重置摊位整数商品数据 */
    initIntShopData_blxf () {
        this._intShopData = null;
    }

    /** 初始化摊位商品标记移除 */
    initVendorMarkRemove_blxf () {
        this.vendorDataList.forEach( vendorItem =>{
            vendorItem.clearShopMarkRemove_blxf();
        })
    }

    /** 获取已解锁摊位数（不包括临时摊位） */
    getUnlockVendorNum_blxf () {
        let { NUM_GOLD, NUM_VIDEO } = EnumManager_blxf.gameNumType;

        let _unlockVendorNum: number = 0;
        let _goldNum: number = NumModule_blxf.instance.getNumByType( NUM_GOLD );

        let { CSV_VENDOR } = EnumManager_blxf.instance.getGameCsvType();
        let _cfgVendorData = CsvManager_blxf.instance.getCsvDataByName_blxf( CSV_VENDOR );

        _cfgVendorData.forEach( vendorItem =>{
            let { VendorId, UnlockType, UnlockNum } = vendorItem;
            let _vendorData: BaseVendorData_blxf = this.findVendorData_blxf( VendorId );
            if ( !_vendorData ) return;

            let _unlockType: number = _vendorData.unlockType;
            let _isUnlock: boolean = _vendorData.onCheckUnlockVendor_blxf();
            let _isVideo: boolean = UnlockType == NUM_VIDEO;

            let _isCanUnlock: boolean = !_isUnlock && !_isVideo;
            // let _isNum: boolean = _goldNum >= Number( UnlockNum );
            let _isNum: boolean = NumModule_blxf.instance.onCheckNum_blxf( _unlockType, Number( UnlockNum ) );
            if ( _isCanUnlock && _isNum ) {
                _isUnlock = true;

                // _goldNum -= UnlockNum;
            }

            let _isAdd: boolean = _isUnlock && _unlockType != 9;
            _isAdd && _unlockVendorNum++;
        })

        return _unlockVendorNum;
    }

    /** 获取摊位商品种类列表 */
    getVendorShopIdList_blxf ( isAddTarget: boolean = false ) {
        let _shopIdList: number[] = [];

        this.vendorDataList.forEach( vendorItem =>{
            vendorItem.shopList.forEach( shopItem =>{
                let _shopId: number = shopItem.getShopId_blxf();
                let _isCheck: boolean = _shopIdList.includes( _shopId );
                let _isCheck2: boolean = _shopId == ConfigModule_blxf.diamondShopId;
                !_isCheck2 && !_isCheck && _shopIdList.push( _shopId );
            })
        })

        // // 添加菜篮子目标商品
        // if ( isAddTarget ) {
        //     let { _targetShopIdList } = this.getTargetAllShopIdList_blxf();
        //     _targetShopIdList.forEach( shopIdItem =>{
        //         let _isCheck: boolean = _shopIdList.includes( shopIdItem );
        //         !_isCheck && _shopIdList.push( shopIdItem );
        //     })
        // }

        return _shopIdList;
    }

    /** 更新菜篮子关卡商品数据 */
    initPassShopInfo_blxf () {
        this.targetDataList.forEach( targetItem =>{
            let _isUnlock: boolean = targetItem.onCheckUnlockTarget_blxf();
            if ( !_isUnlock ) return;

            targetItem.initPassShopInfo_blxf();
        })
    }

    /** 获取上货摊位id列表 */
    getAddShopVendorIdList_blxf () {
        let _vendorIdList: number[] = [ ...this.unlockVendorIdList ];

        // _vendorIdList = _vendorIdList.filter( vendorId =>{
        //     return vendorId != this.videoVendorId;
        // })

        return _vendorIdList;
    }

    /**
     * 获取随机商品id列表
     * @param randomList 随机结果列表
     * @param mustAddShopIdList 随机列表
     * @param randomNum 随机数
     * @returns 返回随机结果
     */
    getAddShopRandomIdList_blxf ( randomList: number[], mustAddShopIdList: number[], randomNum: number ) {
        if ( randomNum <= 0 ) return randomList;

        let _randomItem: number = NumModule_blxf.instance.onRandomListItem_blxf( mustAddShopIdList );

        randomNum -= 1;
        randomList.push( _randomItem );

        return this.getAddShopRandomIdList_blxf( randomList, mustAddShopIdList, randomNum );
    }

    /** 获取菜篮子商品id列表 */
    getTargetShopIdList_blxf () {
        let _shopIdList: number[] = [];

        this.targetDataList.forEach( targetItem =>{
            let _shopId: number = targetItem.getBuyShopId_blxf();
            if ( !_shopId || _shopId == -1 ) return;
            _shopIdList.push( _shopId );
        })

        return _shopIdList;
    }

    /** 获取摊位可添加商品总数 */
    getVendorAddShopMaxNum_blxf ( isProgress: boolean = false ) {
        let _addTotalNum: number = 0, _maxNum: number = 0;

        this.vendorDataList.forEach( targetItem =>{
            let _isUnlock: boolean = targetItem.onCheckUnlockVendor_blxf();
            if ( !_isUnlock ) return;

            let _maxShopNum: number = targetItem.getMaxShopNum_blxf();
            _maxNum += _maxShopNum;

            let _totalNum: number = targetItem.getMaxAddShopNum_blxf();
            _addTotalNum += _totalNum;
        })

        if ( isProgress ) return _addTotalNum / _maxNum;

        return _addTotalNum;
    }

    /** 新增解锁摊位 */
    newAddVendorIdList_blxf ( vendorId: number ) {
        let _vendorData: any = GameData_blxf.instance.getVendorData_blxf( vendorId );
        if ( !_vendorData || _vendorData.vendorId == -1 ) return;

        this.unlockVendorIdList.push( vendorId );

        // 初始化补货数据
        this.initAddShopData_blxf();

        return _vendorData;
    }

    /** 移除摊位id */
    removeVendorId_blxf ( vendorId: number ) {
        let _vendorIndex: number = this.unlockVendorIdList.indexOf( vendorId );
        if ( _vendorIndex == -1 ) return;

        this.unlockVendorIdList.splice( _vendorIndex, 1 );

        this.vendorDataList.forEach( vendorItem =>{
            vendorItem.unlockVendor_blxf( false );
        })
    }

    /** 新增解锁菜篮子 */
    newAddTargetIdList_blxf ( targetId: number ) {
        let _targetData: any = GameData_blxf.instance.getTargetData_blxf( targetId );
        if ( !_targetData || _targetData.targetId == -1 ) return;

        let { isUnlock } = _targetData;
        isUnlock && this.unlockTargetIdList.push( targetId );

        return _targetData;
    }

    /**
     * 检测篮子类型 1：临时篮子、2：普通篮子、3：需求商品篮子
     * @param targetId 篮子id
     * @returns 篮子类型
     */
    onCheckTargetType_blxf ( targetId: number ) {
        let _targetType: number;
        switch ( targetId ) {
            case 1 : _targetType = 1; break;
            case 2 :
            case 4 : _targetType = 2; break;
            case 3 : _targetType = 3; break;
        }
        return _targetType;
    }

    /** 获取游戏菜篮子id */
    getShopTargetId_blxf () {
        return this.shopTargetId;
    }

    /** 获取摊位购买商品信息 */
    getTargetBuyShopInfo_blxf () {
        let _targetData: BaseTargetData_blxf = this.findTargetData_blxf( this.shopTargetId );
        if ( _targetData ) return _targetData.getBuyShopInfo_blxf();
    }

    /** 获取补货商品id */
    getTargetAddShopId_blxf ( addOkNum: number ) {
        let _shopId: number;

        // let _mustShopIdList: number[] = [ ...this.mustAddShopIdList ];
        // let _shopIdList: number[] = GameData_blxf.instance.getShopIdList_blxf();
        // let _isMax: boolean = _mustShopIdList.length >= this.addShopTypeNum;

        // _shopIdList.sort((a, b) => Math.random() - 0.5);
        // !_isMax &&_shopIdList.forEach( shopIdItem =>{
        //     let _isCheck: boolean = _mustShopIdList.includes(shopIdItem);
        //     _isMax = _mustShopIdList.length >= this.addShopTypeNum;
        //     !_isCheck && !_isMax && _mustShopIdList.push( shopIdItem );
        // })

        // _mustShopIdList.sort((a, b) => Math.random() - 0.5);

        // _shopId = _mustShopIdList[0];
        _shopId = this.needAddShopIdList[ addOkNum ];
        // cc.log('上货 >>', addOkNum, _shopId);
        return _shopId;
    }

    /** 获取新商品id */
    getNewShopId_blxf () {
        let _newShopId: number = GameData_blxf.instance.getNewShopId_blxf();
        let _isNewShopId: boolean = _newShopId && _newShopId != -1;
        return _isNewShopId ? _newShopId : null;
    }

    /**
     * 获取需求篮子商品id
     * @param isTarget 是否是目标菜篮子
     * @returns 商品id
     */
    getTargetShopId_blxf ( isTarget: boolean = false, buyShopId: number ) {
        let _shopId: number;
        let _newShopId: number = this.getNewShopId_blxf();
        let _isNewShopId: boolean = /*isTarget &&*/ _newShopId && buyShopId != _newShopId;

        // 其它菜篮子是否已有新商品目标
        let { _targetShopIdList } = VendorData_blxf.instance.getTargetAllShopIdList_blxf();
        let _isNewShopTarget: boolean = _isNewShopId && _targetShopIdList.includes( _newShopId );

        if ( _isNewShopId && !_isNewShopTarget ) {
            _shopId = _newShopId;
        } else {
            let _moreShopIdList: number[] = this.getVendorMoreShopIdList_blxf();
            let _unlockShopIdList: number[] = GameData_blxf.instance.getShopIdList_blxf();

            // 保证下个目标物品和其它菜篮子不重复
            let _otherShopIds: number[] = this.getTargetShopIds_blxf();
            _otherShopIds.push( buyShopId );
            _unlockShopIdList = _unlockShopIdList.filter( item => !_otherShopIds.includes(item));

            let _isMore: boolean = _moreShopIdList.length > 0;
            let _shopIdList: number[] = _isMore ? _moreShopIdList : [ ..._unlockShopIdList ];

            // 保证下个目标物品不重复
            _shopIdList = _shopIdList.filter( item => item != buyShopId );
            
            // 过滤后可能为空(兼容)
            if ( _shopIdList.length == 0 ) _shopIdList = [ ..._unlockShopIdList ];

            // 随机
            let _shopIdLen: number = _shopIdList.length;
            let _shopIndex: number = Math.floor(Math.random() * _shopIdLen);
            _shopId = _shopIdList[ _shopIndex ];
        }

        // 防止出现目标物品鞭炮
        if ( _shopId == ConfigModule_blxf.diamondShopId ) {
            return this.getTargetShopId_blxf( isTarget, buyShopId );
        }
        
        return _shopId;
    }

    /** 获取摊位最多商品id */
    getVendorMaxShopId_blxf ( buyShopId: number, isRandom: boolean = false ) {
        let _maxShopId: number;

        let _shopIds: number[] = this.getTargetShopIds_blxf();
        _shopIds.push( buyShopId );
        _shopIds.push( ConfigModule_blxf.diamondShopId );

        let { _vendorShopIdList } = this.getVendorNumDetail_blxf();
        if ( isRandom ) {
            let _unlockShopIdList: number[] = GameData_blxf.instance.getShopIdList_blxf();
            _vendorShopIdList = _unlockShopIdList.map( shopId =>{
                return { shopId, num: Math.random() * 5 };
            })
        }
        
        // todo 保证和其它菜篮子目标商品不重复
        _vendorShopIdList = _vendorShopIdList.filter( shopItem =>{
            return !_shopIds.includes( shopItem.shopId );
        })

        // 摊位上无不重复商品，随机已解锁商品
        if ( _vendorShopIdList.length == 0 ) {
            return this.getVendorMaxShopId_blxf( buyShopId, true );
        }

        // let _allTargetShopIdList: number[] = this.getTargetShopIds_blxf();
        // _vendorShopIdList = _vendorShopIdList.filter( shopItem => {
        //     return !_allTargetShopIdList.includes( shopItem.shopId );
        // });

        _vendorShopIdList.sort((a, b) => b.num - a.num);

        let _shopData: any = _vendorShopIdList[0]
        _maxShopId = _shopData ? _shopData.shopId : -1;
        
        return _maxShopId;
    }

    /** 获取摊位物品较多的商品id列表 */
    getVendorMoreShopIdList_blxf () {
        let _moreShopIdList: number[] = [];

        let _vendorNum: number = this.getUnlockVendorNum_blxf();
        if ( _vendorNum > 5 ) return _moreShopIdList;

        let _checkNum: number = 5, _shopNumList: any[] = [];
        let _nowShopNum: number = 0, _maxShopNum: number = 0, _numRatio: number = 0.5;

        let _allTargetShopIdList: number[] = this.getTargetShopIds_blxf();

        this.vendorDataList.forEach( vendorItem =>{
            if ( !vendorItem.onCheckUnlockVendor_blxf() ) return;

            vendorItem.shopList.forEach( shopItem =>{
                let _shopId: number = shopItem.getShopId_blxf();
                
                if ( _shopId == ConfigModule_blxf.diamondShopId ) return;

                let _index: number = _shopNumList.findIndex( item => item.shopId == _shopId );
                if ( _index == -1 ) {
                    _shopNumList.push({ shopId: _shopId, num: 1 });
                } else {
                    _shopNumList[ _index ].num += 1;
                    
                    let _isCheck1: boolean = _moreShopIdList.includes( _shopId );
                    let _isCheck2: boolean = _shopNumList[ _index ].num >= _checkNum;
                    // todo 保证和其它菜篮子目标商品不重复
                    let _isCheck3: boolean = _allTargetShopIdList.includes( _shopId );
                    !_isCheck1 && _isCheck2 && !_isCheck3 && _moreShopIdList.push( _shopId );
                }
            })

            _maxShopNum += vendorItem.maxNum;
            _nowShopNum += vendorItem.shopList.length;
        })

        let _isCondition: boolean = NumModule_blxf.instance.onCompareNum_blxf( _nowShopNum, _maxShopNum * _numRatio );
        // cc.log('_moreShopIdList >1>', _isCondition, [ ..._moreShopIdList ]);
        if ( !_isCondition ) _moreShopIdList = [];
        // cc.log('_moreShopIdList >2>', _moreShopIdList, _shopNumList);
        return _moreShopIdList;
    }

    /** 获取摊位商品数量详情 */
    getVendorNumDetail_blxf () {
        let _vendorShopIdList: any[] = [], _vendorIdList: number[] =[];

        this.vendorDataList.forEach( vendorItem =>{
            let _isUnlock: boolean = vendorItem.onCheckUnlockVendor_blxf();
            if ( !_isUnlock ) return;

            let _vendorId: number = vendorItem.vendorId;
            _vendorIdList.push( _vendorId );

            let _maxShopNum = vendorItem.maxNum;
            let _shopIdList: number[] = vendorItem.getShopIdList_blxf();

            _shopIdList.forEach( (shopIdItem, index) =>{

                let _isExtraIcon: boolean = shopIdItem == ConfigModule_blxf.diamondShopId;
                if ( _isExtraIcon ) return;

                let _vendorShopIdIndex: number = _vendorShopIdList.findIndex( item => item.shopId == shopIdItem );
                if ( _vendorShopIdIndex == -1 ) {
                    _vendorShopIdList.push({ shopId: shopIdItem, num: 1, _maxShopNum });
                } else {
                    _vendorShopIdList[ _vendorShopIdIndex ].num += 1;
                }
            })
        })

        return { _vendorShopIdList, _vendorIdList };
    }

    

    /** 获取上货总数 */
    getAddShopTotalNum_blxf () {
        let _addTotalNum: number = this.addShopTotalNum;
        
        // 额外上货(已废弃)
        // let _isExtra: boolean = this.onCheckExtraAddShop_blxf();
        // if ( _isExtra ) {
        //     _addTotalNum += this.extraShopTotalNum;
        // }

        let _isGui: boolean = GameData_blxf.instance.getIsGuidance_blxf();
        if ( !_isGui ) _addTotalNum = 12;
        
        return _addTotalNum;
    }

    /** 检测是否触发额外上货 */
    onCheckExtraAddShop_blxf () {
        let _isExtra: boolean;

        if ( PublicModule_blxf.isRemoveShop ) {
            _isExtra = true;
        } else {
            _isExtra = this.onCheckVendorShopNum_blxf();
        }
        
        return _isExtra;
    }

    /**
     * 检测摊位商品数是否低于最小值
     * @param checkType 1: 剩余商品数、2: 剩余商品百分比
     * @returns 返回检测结果
     */
    onCheckVendorShopNum_blxf ( checkType: number = 1 ) {
        let _isCheck: boolean;
        let _vendorNum: number = 0;
        let _shopTotalNum: number = 0;
        let _maxShopNum: number = 0;
        
        this.vendorDataList.forEach( vendorItem =>{
            if ( !vendorItem.onCheckUnlockVendor_blxf() ) return;

            let _vendorShopNum: number = vendorItem.getShopNum_blxf();
            let _vendorMaxNum: number = vendorItem.getMaxShopNum_blxf();

            _vendorNum += 1;
            _shopTotalNum += _vendorShopNum;
            _maxShopNum += _vendorMaxNum;
        })

        let _checkShopNum: number, _checkNum: number, _isEqual: boolean;
        let { checkShopNum, checkShopPercent } = ConfigModule_blxf;
        switch ( checkType ) {
            case 1 :
                _checkNum = _shopTotalNum, _isEqual = true;
                _checkShopNum = NumModule_blxf.instance.onEval_blxf( checkShopNum, 'N', _vendorNum ); 
                break;

            case 2 :
                _checkNum = 1 - _shopTotalNum / _maxShopNum, _isEqual = false;
                _checkShopNum = NumModule_blxf.instance.changeNum_blxf( checkShopPercent );
                break;
        }
        _isCheck = NumModule_blxf.instance.onCompareNum_blxf( _checkShopNum, _checkNum, _isEqual );

        // cc.log('_checkShopNum: ', _checkShopNum, _shopTotalNum, _isCheck);
        return _isCheck;
    }

    /**
     * 根据摊位id获取摊位数据
     * @param vendorId 摊位id
     * @returns 摊位数据
     */
    findVendorData_blxf ( vendorId: number ) {
        let _vendorData: BaseVendorData_blxf;

        if ( !vendorId || vendorId < 1 ) {
            UtilsModule_blxf.instance.Log_blxf(`getVendorData_blxf 参数错误 vendorId = ${vendorId}`, 2);
            return _vendorData;
        }

        _vendorData = this.vendorDataList.find( item =>{
            return item.vendorId == vendorId;
        })

        return _vendorData;
    }

    /**
     * 更加篮子id获取篮子数据
     * @param targetId 菜篮子id
     * @returns 菜篮子数据
     */
    findTargetData_blxf ( targetId: number ) {
        let _targetData: BaseTargetData_blxf;

        if ( !targetId || targetId < 1 ) {
            UtilsModule_blxf.instance.Log_blxf(`findTargetData_blxf 参数错误 targetId = ${targetId}`, 2);
            return _targetData;
        }

        _targetData = this.targetDataList.find( item =>{
            return item.targetId == targetId;
        })

        return _targetData;
    }

    /** 获取摊位购买商品信息 */
    onTargetBuyShopIdInfo_blxf () {
        let _targetInfo: object = {};

        this.targetDataList.forEach( targetDataItem =>{
            let _targetId: number = targetDataItem.getTargetId_blxf();
            let _buyshopId: number = targetDataItem.getBuyShopId_blxf();
            _targetInfo[ _buyshopId ] = _targetId;
        })

        return _targetInfo;
    }

    /**
     * 查找商品数据
     * @param shopId 商品id
     * @returns 商品数据
     */
    findShopData_blxf ( shopId: number ) {
        let _shopData: any;

        let _GameCsvType = EnumManager_blxf.instance.getGameCsvType();
        let _shopCfgList = CsvManager_blxf.instance.getCsvDataByName_blxf( _GameCsvType.CSV_SHOP );

        _shopData = _shopCfgList.find( item => item.ShopId == shopId );
        if ( shopId && !_shopData ) return _shopData;

        return shopId ? _shopData : _shopCfgList;
    }

    /** 获取过关商品信息 */
    getTargetPassShopInfo_blxf () {
        let _targetData: BaseTargetData_blxf = this.findTargetData_blxf( this.shopTargetId );
        let _passShopInfo = _targetData.getPasShopInfo_blxf();

        return _passShopInfo;
    }
    
    /**
     * 获取摊位数据列表
     * @returns 返回摊位列表
     */
    getVendorDataList_blxf () {
        return this.vendorDataList;
    }

    /**
     * 摊位上货
     * @param vendorId 上货摊位id
     * @param shopId 上货商品id
     * @param return 返回商品数据
     */
    addVendorShop_blxf ( vendorId: number, shopId: number, isExtraIcon: boolean, isShowSpine: boolean = false ) {
        let _addShopData: BaseShopData_blxf;
        if ( !vendorId || !shopId ) {
            // UtilsModule_blxf.instance.Log_blxf(`摊位上货 参数错误 >> vendorId = ${vendorId}, shopId = ${shopId}`, 2);
            return _addShopData;
        }

        let _vendorIndex: number = vendorId - 1;
        let vendorData: BaseVendorData_blxf = this.vendorDataList[ _vendorIndex ]; 
        _addShopData = vendorData.addShop_blxf( shopId, true, isExtraIcon, isShowSpine );

        _addShopData && GameData_blxf.instance.updateBtnShopNum_blxf( -1 * this.baseShopNum );

        return _addShopData;
    }

    /** 检测是否出现单个商品 */
    onCheckVendorShop_blxf () {
        this.vendorDataList.forEach( vendorItem =>{
            let _isUnlock: boolean = vendorItem.onCheckUnlockVendor_blxf();
            if ( !_isUnlock ) return;

            vendorItem.onCheckShop_blxf();
        })
    }

    /** 摊位卸货 */
    onRemoveVendorShop_blxf ( markNum: number = 0, isTouchRemove: boolean = false ) {
        let _vendorNum: number = this.getUnlockVendorNum_blxf();
        let _removeData: any = CsvManager_blxf.instance.getVendorRemoveShopData_blxf( _vendorNum );
        let _removeTotalNum: number = _removeData ? _removeData.RemoveNum / this.baseShopNum : 14 / this.baseShopNum;
        _removeTotalNum = 999;

        this.clearMarkVendorId_blxf();

        // 需求商品id
        let _shopIds: number[] = [ ConfigModule_blxf.diamondShopId ];
        this.targetDataList.forEach( targetItem =>{
            let _shopId: number = targetItem.getBuyShopId_blxf();
            _shopId && _shopId != -1 && !_shopIds.includes(_shopId) && _shopIds.push( _shopId );
        })
        if ( _shopIds.length == 0 ) return;

        let _shopId: number = this.onTargetShopId_blxf( this.shopTargetId );
        if ( !_shopId ) return;

        // // 获取摊位整数商品数据
        // !isTouchRemove && this.onIntShopData_blxf( _shopIds );

        let _index: number = _shopIds.indexOf( _shopId );
        let _resArr: number[] = _shopIds.splice( _index, 1 );
        _shopIds.unshift( _resArr[0] )

        let _markNum: number = markNum;
        this.vendorDataList.forEach( vendorItem =>{
            let _isUnlock: boolean = vendorItem.onCheckUnlockVendor_blxf();
            if ( !_isUnlock ) return;
            if ( markNum >= _removeTotalNum ) return;

            let _isRemove: boolean = vendorItem.removeShopByNum_blxf( _shopIds, 1, this._intShopData || [] );
            _isRemove = vendorItem.removeShopByNum_blxf( _shopIds, 1, this._intShopData || [] );
            if ( !_isRemove ) return;

            markNum += 2;
        })

        let _isCheckRemove: Boolean = markNum > _markNum;
        if ( !_isCheckRemove ) return UtilsModule_blxf.instance.Log_blxf(`摊位没有多余商品可卸货`);

        let _isRemoveOk: boolean = markNum >= _removeTotalNum;
        !_isRemoveOk && this.onRemoveVendorShop_blxf( markNum );
    }

    /**
     * 获取摊位整数商品数据
     * @param targetShopIds 菜篮子目标商品id
     */
    onIntShopData_blxf ( targetShopIds: number[] ) {
        if ( this._intShopData ) return;

        let _intShopData: any[] = [];
        let { _vendorShopIdList } = this.getVendorNumDetail_blxf();
        _vendorShopIdList.forEach( shopItem =>{
            let { shopId, num, _maxShopNum } = shopItem;
            let _isCheck1 = targetShopIds.includes( shopId );
            let _isCheck2 = num >= _maxShopNum;
            if ( _isCheck1 || !_isCheck2 ) return;

            let _int = Math.floor( num / _maxShopNum );
            num = _int * _maxShopNum;
            _intShopData.push({ shopId, num });
        })

        this._intShopData = _intShopData;
    }

    /** 摊位重装 */
    onRestartVendorShop_blxf () {
        this.onRestartVendorShop_blxf_test();
        return;

        // 需求商品id
        let _shopIds: number[] = [];
        this.targetDataList.forEach( targetItem =>{
            let _shopId: number = targetItem.getBuyShopId_blxf();
            _shopId && _shopId != -1 && !_shopIds.includes(_shopId) && _shopIds.push( _shopId );
        })
        if ( _shopIds.length == 0 ) return;

        // 需求商品id
        let _shopId: number = this.onTargetShopId_blxf( this.shopTargetId );
        // if ( !_shopId ) return;

        let _index: number = _shopIds.indexOf( _shopId );
        let _resArr: number[] = _shopIds.splice( _index, 1 );
        _shopIds.unshift( _resArr[0] )

        this.vendorDataList.forEach( vendorItem =>{
            let _isUnlock: boolean = vendorItem.onCheckUnlockVendor_blxf();
            if ( !_isUnlock ) return;

            vendorItem.onRestartShopList_blxf( _shopIds );
        })
    }

    /** 获取所有菜篮子目标商品id列表 */
    getTargetShopIds_blxf () {
        //  需求商品id
        let _shopIds: number[] = [];

        this.targetDataList.forEach( targetItem =>{
            let _shopId: number = targetItem.getBuyShopId_blxf();
            _shopId && _shopId != -1 && !_shopIds.includes(_shopId) && _shopIds.push( _shopId );
        })

        return _shopIds;
    }

    /** 摊位重装 */
    onRestartVendorShop_blxf_test () {
        // 是否过关清除
        let _isPassClearExtra: boolean = PublicModule_blxf.isPassClearExtra;
        // 需求商品id
        let _shopIds: number[] = this.getTargetShopIds_blxf();

        // 需求商品id
        let _shopId: number = this.onTargetShopId_blxf( this.shopTargetId );
        // if ( !_shopId ) return;

        let _index: number = _shopIds.indexOf( _shopId );
        let _resArr: number[] = _shopIds.splice( _index, 1 );
        _shopIds.unshift( _resArr[0] )

        let _vendorShopIdList: any[] = [], _vendorIdList: number[] =[];

        this.vendorDataList.forEach( vendorItem =>{
            let _isUnlock: boolean = vendorItem.onCheckUnlockVendor_blxf();
            if ( !_isUnlock ) return;

            let _vendorId: number = vendorItem.vendorId;
            let _isVideoVendor: boolean = vendorItem.onCheckVideoVendor_blxf();
            if ( !_isVideoVendor || !_isPassClearExtra ) _vendorIdList.push( _vendorId );

            // vendorItem.onRestartShopList_blxf( _shopIds );
            let _maxShopNum = vendorItem.maxNum;
            let _shopIdList: number[] = vendorItem.getShopIdList_blxf();
            let _extraIconList: boolean[] = vendorItem.getShopExtraList_blxf();
            _shopIdList.forEach( (shopIdItem, index) =>{
                let _isExtraIcon: boolean = _extraIconList[ index ];
                let _addExtraIconNum: number = _isExtraIcon ? 1 : 0;

                let _index = _shopIds.indexOf( shopIdItem );
                let _vendorShopIdIndex: number = _vendorShopIdList.findIndex( item => item.shopId == shopIdItem );
                if ( _vendorShopIdIndex == -1 ) {
                    let _sortNum: number = _index > -1 ? (1000 - _index) * 100 : index;
                    _vendorShopIdList.push({ shopId: shopIdItem, num: 1, extraIconNum: _addExtraIconNum, sortNum: _sortNum, _maxShopNum });
                } else {
                    _vendorShopIdList[ _vendorShopIdIndex ].num += 1;
                    _vendorShopIdList[ _vendorShopIdIndex ].sortNum += 100;
                    _vendorShopIdList[ _vendorShopIdIndex ].extraIconNum += _addExtraIconNum;
                }
            })
        })

        // // 过滤未集满鞭炮（20240401）
        // _vendorShopIdList = _vendorShopIdList.filter( item =>{
        //     // if ( !PublicModule_blxf.isPassClearExtra ) return true;
            
        //     let { shopId, num, _maxShopNum } = item;
        //     let _isExtra: boolean = shopId == ConfigModule_blxf.diamondShopId;
        //     return !_isExtra || num >= _maxShopNum;
        // })
        PublicModule_blxf.isPassClearExtra = false;

        _vendorShopIdList.sort((a, b) => b.sortNum - a.sortNum);
        // cc.log('_vendorShopIdList >1>', _vendorShopIdList, _vendorIdList);

        let _vendorInfoList: any[] = [];
        _vendorShopIdList.forEach( item =>{
            let { sortNum, shopId, num, _maxShopNum, extraIconNum } = item;
            let _index: number = _vendorInfoList.length;
            let _markIndex: number = _index;
            if ( _index < _vendorIdList.length - 2 ) {
                let _isGtMax: boolean = num > _maxShopNum;
                if ( _isGtMax ) {
                    num -= _maxShopNum;
                    let _extraIconNum = extraIconNum > _maxShopNum ? _maxShopNum : extraIconNum;
                    if ( _extraIconNum < 0 ) _extraIconNum = 0;
                    extraIconNum -= _maxShopNum;
                    _vendorInfoList.push({
                        vendorId: _vendorIdList[ _index ],
                        shopList: [{ shopId, num: _maxShopNum, extraIconNum: _extraIconNum }]
                    })

                    _index += 1;
                }

                _isGtMax = num > _maxShopNum;
                if ( _isGtMax ) {
                    num -= _maxShopNum;
                    let _extraIconNum = extraIconNum > _maxShopNum ? _maxShopNum : extraIconNum;
                    if ( _extraIconNum < 0 ) _extraIconNum = 0;
                    extraIconNum -= _maxShopNum;
                    _vendorInfoList.push({
                        vendorId: _vendorIdList[ _index ],
                        shopList: [{ shopId, num: _maxShopNum, extraIconNum: _extraIconNum }]
                    })

                    _index += 1;
                }

                _isGtMax = num > _maxShopNum;
                if ( _isGtMax ) {
                    num -= _maxShopNum;
                    let _extraIconNum = extraIconNum > _maxShopNum ? _maxShopNum : extraIconNum;
                    if ( _extraIconNum < 0 ) _extraIconNum = 0;
                    extraIconNum -= _maxShopNum;
                    _vendorInfoList.push({
                        vendorId: _vendorIdList[ _index ],
                        shopList: [{ shopId, num: _maxShopNum, extraIconNum: _extraIconNum }]
                    })

                    _index += 1;
                }

                _isGtMax = num > _maxShopNum;
                if ( _isGtMax ) {
                    num -= _maxShopNum;
                    let _extraIconNum = extraIconNum > _maxShopNum ? _maxShopNum : extraIconNum;
                    if ( _extraIconNum < 0 ) _extraIconNum = 0;
                    extraIconNum -= _maxShopNum;
                    _vendorInfoList.push({
                        vendorId: _vendorIdList[ _index ],
                        shopList: [{ shopId, num: _maxShopNum, extraIconNum: _extraIconNum }]
                    })

                    _index += 1;
                }

                if ( _index > _markIndex ) return;

                if ( extraIconNum < 0 ) extraIconNum = 0;
                num > 0 && _vendorInfoList.push({
                    vendorId: _vendorIdList[ _index ],
                    shopList: [{ shopId, num, extraIconNum }]
                })
            } else {
                // for ( let i = _index - 1; i >= 0; i-- ){
                //     if ( num <= 0 ) continue;

                //     let _vendorTotalNum: number = 0;
                //     let _totalShopNum: number = _vendorInfoList[i].shopList.length;
                //     for( let j = 0; j < _totalShopNum; j++ ){
                //         _vendorTotalNum += _vendorInfoList[i].shopList[j].num;
                //     }
                //     let _needNum = _maxShopNum - _vendorTotalNum;
                    
                //     if ( _needNum <= 0 ) continue;

                //     if ( num > _needNum ) {
                //         num -= _needNum;
                //         let _extraIconNum = extraIconNum > _needNum ? _needNum : extraIconNum;
                //         if ( _extraIconNum < 0 ) _extraIconNum = 0;
                //         extraIconNum -= _needNum;
                //         _vendorInfoList[i].shopList.push({ shopId, num: _needNum, extraIconNum: _extraIconNum });

                //         continue;
                //     }
                    
                //     if ( extraIconNum < 0 ) extraIconNum = 0;
                //     _vendorInfoList[i].shopList.push({ shopId, num, extraIconNum })
                //     num = 0;
                // }
            }
        })

        _vendorInfoList.forEach( item =>{
            item.shopList.reverse();
        })
        // cc.log('_vendorShopIdList >2>', _vendorInfoList);

        this.vendorDataList.forEach( vendorItem =>{
            let _isUnlock: boolean = vendorItem.onCheckUnlockVendor_blxf();
            if ( !_isUnlock ) return;

            let _vendorId: number = vendorItem.vendorId;
            let _data: any = _vendorInfoList.find( item => item.vendorId == _vendorId );
            if ( !_data ) return vendorItem.onRestartShopList_blxf_test( [] );

            let _newShopIdList: number[] = [];
            let extraIconNumInfo: any = {};
            _data.shopList.forEach( shopInfoItem =>{
                let { shopId, num, extraIconNum } = shopInfoItem;
                let _idArr: number[] = [];
                _idArr.length = num;
                _idArr.fill(shopId, 0, num);
                _newShopIdList = _newShopIdList.concat( _idArr);

                extraIconNumInfo[ shopId ] = extraIconNum || 0;
            })
            vendorItem.onRestartShopList_blxf_test( _newShopIdList, extraIconNumInfo );
        })
    }

    /** 获取标记摊位id */
    getMarkVendorId_blxf () {
        return this.markVendorId;
    }

    /** 检测是否有标记摊位 */
    onCheckMarkVendorId_blxf () {
        return this.markVendorId != -1;
    }

    /** 添加标记摊位 */
    addMarkVendorId_blxf ( vendorId: number ) {
        this.markVendorId = vendorId;

        // UtilsModule_blxf.instance.Log_blxf(`《1》添加标记摊位 >> ${vendorId}`);
    }

    /** 清除标记摊位 */
    clearMarkVendorId_blxf () {
        this.markVendorId = -1;
    }

    /** 获取摊位商品id(默认标记摊位) */
    onVendorShopId_blxf ( vendorId: number = this.markVendorId ) {
        let _vendorData: BaseVendorData_blxf = this.findVendorData_blxf( vendorId );
        let _markShopId: number = _vendorData.onCheckShopId_blxf();

        return _markShopId;
    }

    /**
     * 获取菜篮子商品id
     * @param targetId 菜篮子id
     */
    onTargetShopId_blxf ( targetId: number ) {
        let _shopId: number;

        let _targetData: BaseTargetData_blxf = this.findTargetData_blxf( targetId );
        if ( !_targetData ) {
            UtilsModule_blxf.instance.Log_blxf(`onTargetShopId_blxf 查找菜篮子商品失败 >>`, 2);
            return _shopId;
        }

        _shopId = _targetData.getBuyShopId_blxf();
        return _shopId;
    }

    /**
     * 获取客人信息
     * @param guestId 客人id
     */
    getGuestInfo_blxf ( guestId: number = null ) {
        let { CSV_GUEST } = EnumManager_blxf.instance.getGameCsvType();
        let _cfgGuestList: any[] = CsvManager_blxf.instance.getCsvDataByName_blxf( CSV_GUEST );
        _cfgGuestList.forEach( guestItem =>{
            let { GuestId, GuestName, AtlasName, ImgName } = guestItem;
            let _isUnlock: boolean = GameData_blxf.instance.onIsUnlockGuest_blxf( Number(GuestId) );
            let _isNew: boolean = GameData_blxf.instance.onIsNewGuest_blxf( Number(GuestId) );
            if ( _isNew ) _isNew = GameData_blxf.instance.onCheckGuestId_blxf( Number(GuestId) );
            guestItem['guestName'] = GuestName;
            guestItem['path'] = `${AtlasName}`;
            guestItem['imgName'] = ImgName;
            guestItem['isUnlock'] = _isUnlock;
            guestItem['isNew'] = _isNew;

            // 喜爱物品相关数据
            let { LikeShopId } = guestItem;
            if ( !LikeShopId ) return;

            let _likeShopData: any;
            if ( GuestId < 100 ) {
                _likeShopData = CsvManager_blxf.instance.getShopData_blxf( LikeShopId );
            } else {
                _likeShopData = CsvManager_blxf.instance.getBuildData_blxf( LikeShopId );
            }

            guestItem['shopPath'] = _likeShopData.AtlasName;
            guestItem['shopImg'] = _likeShopData.ImgName;
            guestItem['shopName'] = _likeShopData.ShopName || _likeShopData.Name;
            guestItem['shopSellNum'] = _likeShopData.SellNum;
        })
        let _guestData: any = _cfgGuestList.find( guestItem => guestItem.GuestId == guestId );
        return guestId ? _guestData : _cfgGuestList;

        UtilsModule_blxf.instance.Log_blxf(`获取客人信息失败 guestId => ${guestId}`);
    }

    /** 清除游戏数据 */
    onClearAllGameData () {
        PublicModule_blxf.isRestartGame = true;
        PublicModule_blxf.restartBfVendorIdList = [ ...this.unlockVendorIdList ];

        GameData_blxf.instance.clearData_blxf();
        GameData_blxf.instance.loadGameData_blxf();

        this.markVendorId = -1;
        this.targetDataList.length = 0;
        this.vendorDataList.length = 0;
        this.unlockVendorIdList.length = 0;
        this.unlockTargetIdList.length = 0;

        // 重新加载自动售卖界面
        cc.game.emit('onRestartAutoSaclePanel_blxf');
    }

    /** 重进游戏检测是否清除数据 */
    onCheckConnectClear_blxf () {
        // let _addShopMaxNum: number = this.getVendorAddShopMaxNum_blxf();
        // let _isClear: boolean = _addShopMaxNum == 0;
        // if ( !_isClear ) return;

        // let _isMove: boolean = this.onCheckShopMove_blxf();
        // if ( _isMove ) return;

        // 摊位清空
        this.vendorDataList.forEach( vendorItem =>{
            vendorItem.clearShop_blxf();
        })

        // 目标商品清零
        this.targetDataList.forEach( targetItem =>{
            targetItem.clearTarget_blxf();
        })

        // 关卡进度清零
        GameData_blxf.instance.setPassShopNum_blxf( 0 );
    }

    /** 检测摊位商品是否可移动至菜篮子 */
    onCheckShopMove_blxf () {
        let _isMove: boolean = false;

        let _targetShopIdList: number[] = [];
        this.targetDataList.forEach( targetItem =>{
            let _targetShopId: number = targetItem.getBuyShopId_blxf();
            if ( !_targetShopId || _targetShopId == -1 ) return;

            let _isCheck = _targetShopIdList.includes( _targetShopId );
            !_isCheck && _targetShopIdList.push( _targetShopId );
        })

        this.vendorDataList.forEach( vendorItem =>{
            if ( _isMove ) return;
            let _vendorShopId: number = vendorItem.onCheckShopId_blxf();
            if ( !_vendorShopId || _vendorShopId == -1 ) return;

            let _isAllShop: boolean = vendorItem.onCheckIsAllShop_blxf();
            if ( !_isAllShop ) return;

            _isMove = true;
            // _isMove = _targetShopIdList.includes( _vendorShopId );
        })

        return _isMove;
    }

    /** 检测是否有满商品 */
    getVendorAllShopIdList_blxf ( vendorId: number = -1, isTargetId: boolean = false, isCheckBtn: boolean = false ) {
        let _vendorShopIdList: number[] = [];
        let _vendorIdList: number[] = [];

        this.vendorDataList.forEach( vendorItem =>{
            let _isUnlock: boolean = vendorItem.onCheckUnlockVendor_blxf();
            if ( !_isUnlock ) return;

            // 检测是否是检测摊位
            let _vendorId: number = vendorItem.vendorId;
            if ( vendorId != -1 && _vendorId != vendorId ) return;

            let _isAll: boolean = vendorItem.onCheckIsAllShop_blxf(); 
            if ( !_isAll ) return;

            let _shopId: number = vendorItem.onCheckShopId_blxf();

            if ( !isCheckBtn && _shopId == ConfigModule_blxf.diamondShopId ) return;

            _vendorShopIdList.push( _shopId );
            _vendorIdList.push( _vendorId );
        })

        return isTargetId ? _vendorIdList : _vendorShopIdList;
    }

    /** 获取菜篮子目标商品id列表 */
    getTargetAllShopIdList_blxf () {
        let _isNullTarget: boolean = false;
        let _targetShopIdList: number[] = [];

        this.targetDataList.forEach( targetItem =>{
            let _isUnlock: boolean = targetItem.onCheckUnlockTarget_blxf();
            if ( !_isUnlock ) return;

            // 临时蓝不参与检测
            let _isVideo: boolean = targetItem.getBuyShopId_blxf() == -1;
            if ( _isVideo ) return;

            let _shopId: number = targetItem.getBuyShopId_blxf();
            if ( !_shopId || _shopId == -1 ) return _isNullTarget = true;

            _targetShopIdList.push( _shopId );
        })

        return { _targetShopIdList, _isNullTarget };
    }

    /** 获取有空位摊位id */
    getNullVendorId_blxf () {
        let _vendorIdList: number[] = [];

        this.vendorDataList.forEach( vendorItem =>{
            let _isUnlock: boolean = vendorItem.onCheckUnlockVendor_blxf();
            if ( !_isUnlock ) return;

            let _isVideo: boolean = vendorItem.onCheckVideoVendor_blxf();
            if ( _isVideo ) return;

            let _addNum: number = vendorItem.getMaxAddShopNum_blxf();
            if ( _addNum <= 0 ) return;

            let _vendorId = vendorItem.getVendorId_blxf();
            _vendorIdList.push( _vendorId );
        })

        return _vendorIdList[0];
    }

    /** 获取随机对联文字 */
    onRandomCoupletText_blxf () {
        let _coupletId: number, _coupletType: number, _textIndex: number;

        let { CSV_COUPLET  } = EnumManager_blxf.instance.getGameCsvType();
        let _coupletList = CsvManager_blxf.instance.getCsvDataByName_blxf( CSV_COUPLET );

        let _isAll: boolean = true, _isRandom: boolean = false, _coupletItem: any;

        _coupletList.forEach( coupletItem =>{
            let { CoupletId } = coupletItem;
            
            // todo new add check;
            if ( !_isAll ) return;

            if ( _isRandom ) return;

            let _unList: number[][] = GameData_blxf.instance.onCheckCoupletState_blxf( Number(CoupletId), !_isAll );

            if ( !_unList ) return;

            let _coupletTypes: number[] = [];
            _unList.forEach( (listItem, index) =>{
                if ( listItem.length == 0 ) return;

                _coupletTypes.push( index + 1 );
            })

            if ( _coupletTypes.length == 0 ) return;

            _isAll = false;
            _coupletId = Number(CoupletId);
            
            _coupletTypes.sort((a, b) => Math.random() - 0.5);
            _coupletType = _coupletTypes[ 0 ];

            let _textIndexs: number[] = _unList[ _coupletType - 1 ];
            _textIndexs.sort((a, b) => Math.random() - 0.5);
            _textIndex = _textIndexs[ 0 ];

            _coupletItem = coupletItem;
        })

        if ( _coupletId === undefined || _coupletType === undefined || _textIndex == undefined ) return;

        _isRandom = true;

        PublicModule_blxf.isMoveAnimation = true;

        // 保存解锁对联文字
        GameData_blxf.instance.unlockCouplet_blxf( _coupletId, _coupletType, _textIndex );

        // 对联解锁完整
        let _isUnlockOk: boolean = this.onCheckCoupletUnlockOk_blxf( _coupletId );
        _isUnlockOk && GameData_blxf.instance.updateCoupletNewState_blxf( _coupletId, true );

        // 返回解锁对联文字
        let { CoupletLeft, CoupletRight, CoupletTop } = _coupletItem;
        let _texts: string = [ CoupletLeft, CoupletRight, CoupletTop ][ _coupletType - 1 ].split('');
        let _coupletText = _texts[ _textIndex ];
        return _coupletText;
    }

    /** 检测对联是否解锁成功（方法1） */
    onCheckCoupletUnlockOk_blxf ( coupletId: number ) {
        let _isUnlockOk: boolean = true;
        
        let _unList: number[][] = GameData_blxf.instance.onCheckCoupletState_blxf( coupletId, true );
        if ( _unList.length == 0 ) return _isUnlockOk;

        _unList.forEach( item =>{
            if ( !_isUnlockOk ) return;
            if ( item.length == 0 ) return;

            _isUnlockOk = false;
        })

        return _isUnlockOk;
    }

    // /** 检测对联是否解锁（方法2） */
    // onCheckCoupletUnlock_blxf ( coupletId: number ) {
    //     let { CSV_COUPLET  } = EnumManager_blxf.instance.getGameCsvType();
    //     let _coupletList = CsvManager_blxf.instance.getCsvDataByName_blxf( CSV_COUPLET );

    //     let _coupletData: any = _coupletList.find( item => item.CoupletId == coupletId );
    //     if ( !_coupletData ) return;

    //     let { CoupletId, CoupletLeft, CoupletRight, CoupletTop } = _coupletData;

    //     let _stateList1 = this.onCoupletStateList_blxf( CoupletId, 1, CoupletLeft );
    //     let _stateList2 = this.onCoupletStateList_blxf( CoupletId, 2, CoupletRight );
    //     let _stateList3 = this.onCoupletStateList_blxf( CoupletId, 3, CoupletTop );

    //     let _isAllUnlock = !_stateList1.includes( false ) && !_stateList2.includes( false ) && !_stateList3.includes( false );
    //     return _isAllUnlock;
    // }

    // /** 对联状态列表 */
    // onCoupletStateList_blxf ( coupletId: number, coupletType: number, coupletText: string ) {
    //     let _stateList: boolean[] = [];

    //     let _texts: string[] = coupletText.split('');
    //     _texts.forEach( (item, index) =>{
    //         let _state: boolean = GameData_blxf.instance.onCheckCouplet_blxf( coupletId, coupletType, index );
    //         _stateList.push( _state );
    //     })

    //     return _stateList;
    // }

    /** 更新摊位等级 */
    updateVendorLevel_blxf ( vendorId: number, addLv: number ) {
        let _vendorData: BaseVendorData_blxf = this.findVendorData_blxf( vendorId );
        _vendorData.setVendorLevel_blxf( addLv );
    }

    /** 重置视频摊位 */
    onRestartVideoVendor_blxf () {
        this.vendorDataList.forEach( vendorItem =>{
            let _isRestart: boolean = vendorItem.onRestartVideoVendor_blxf();
            _isRestart && vendorItem.clearVendorShopList_blxf();
        })
    }
}
